import re
class ValidationContrainte:
    def __init__(self):
        self.Operande = {"<":self.plusPetit, 
                         ">":self.plusGrand,
                         "<=":self.plusPetit_Egal,
                         ">=":self.plusGrand_Egal,
                         "=":self.Egal}
        
    
    def getOperande(self):
        return self.Operande.keys()
    
    def plusPetit(self, gauche, droite):
        if gauche < droite:
            return 1
        else:
            return 0
        
    def plusGrand(self, gauche, droite):
        if gauche > droite:
            return 1
        else:
            return 0
    
    def plusPetit_Egal(self, gauche, droite):
        if gauche <= droite:
            return 1
        else:
            return 0
    
    def plusGrand_Egal(self, gauche, droite):
        if gauche >= droite:
            return 1
        else:
            return 0
    
    def Egal(self, gauche, droite):
        if gauche == droite:
            return 1
        else:
            return 0
    
    def validerEntier(self, entier):
        try:
            first = int(entier)
            return True
        except ValueError:
                return False
    
    
    def validerReel(self, reel):
        try:
            first = float(reel)
            return True
        except ValueError:
                return False
    
    def validerPhone(self,phone): 
       log = re.compile('\d{3}[-]\d{3}[-]\d{4}',re.IGNORECASE)
       result = log.match(phone)
       if result:
          return True                 
       else:
           return False
          
    def validerDate(self,date): 
       print date
       log = re.compile('\d{2}[/]\d{2}[/]\d{2}',re.IGNORECASE)
       result = log.match(date)
       if result:
          return True                 
       else:
           return False
           
    def validerNAS(self,nas): 
       log = re.compile('\d{3}[-]\d{3}[-]\d{3}',re.IGNORECASE)
       result = log.match(nas)
       if result:
          return True                 
       else:
           return False
       
    def validerNom(self,nom):
        if len(nom) >= 2:
            return True  
        else:
            return False
        
    def validerCodePostal(self,CodeP):
        if(len(codeP==7)): 
           log = re.compile('\d{3}[-]\d{3}',re.IGNORECASE)
           result = log.match(codeP)
           if result:
              return True 
           else:
               return false                          
        else:
            return False
        